//
//  AppDelegate.m
//  上海杨浦
//
//  Created by FrankChen on 13-3-25.
//  Copyright (c) 2013年 FrankChen. All rights reserved.
//

#import "AppDelegate.h"


@implementation AppDelegate



-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
    if ([[url scheme] isEqualToString:@"shyp"]) {
        return YES;
    }
    return NO;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
//    NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    //NSLog(@"当前应用软件版本:%@",appCurVersion);
    
//    @try {
//        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
//        [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",@"666701015"]]];
//        [request setHTTPMethod:@"GET"];
//        NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
//        NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:returnData options:0 error:nil];
//        
//        NSString *latestVersion=@"";
//        
//        for (NSDictionary *info in [jsonData objectForKey:@"results"]) {
//            latestVersion=[info objectForKey:@"version"];
//        }
//        
//        //NSLog(@"当前应用软件版本:%@",latestVersion);
//        
//        if (![latestVersion isEqualToString:appCurVersion]) {
//            [self alertUpdate:@"进行更新"];
//        }
//    }
//    @catch (NSException *exception) {
//        UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"网络连接失败，请先检查您的网络。" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];
//        [alert show];
//    }
//    @finally {
//        
//    }

    
    return YES;
}

- (void)alertView:(UIAlertView *)alertView
didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex != [alertView cancelButtonIndex])
    {
        NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/us/app/shang-hai-yang-pu/id666701015?ls=1&mt=8"];
        [[UIApplication sharedApplication] openURL:url];
    }
}
-(void)alertUpdate:(NSString *)strContent
{
        UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"升级提示"
                                                      message:strContent
                                                     delegate:self       //委托给Self，才会执行上面的调用
                                            cancelButtonTitle:@"以后再说"
                                            otherButtonTitles:@"马上更新",nil] autorelease];
        [av show];
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
